// 先来看看浅拷贝
let obj={
    name:"xiaoyu",
    addr:{ip:520,gxr:{desc:"呆呆，你在干嘛"}}
};

function clone(obj){
    const o={}
    for(let key in obj){
        o[key]=obj[key];
    }
    return o;
}

let cloneObj=clone(obj);
cloneObj.name="xinrou";
cloneObj.addr.ip=1314;
cloneObj.addr.gxr.desc="有没有想我了"
console.log(obj,cloneObj);

let clone2=Object.assign(obj);
console.log(clone2);
let clone3=Object.create(obj);
console.log(clone3);


// 进行深拷贝
function deepClone(obj){
    const newobj=(obj instanceof Array?[]:{});
    for(let key in obj){
        if(obj[key] instanceof Object){
            newobj[key]=deepClone(obj[key]);
        }else{
            newobj[key]=obj[key];
        }
    }
    return newobj;
}
let deepObj=deepClone(obj);
deepObj.addr.gxr.desc="还能在一起吗";
console.log(deepObj);

// 还能
// JSON.stringify()
// JSON.parse()